<style>
    .color-red {
        color: #e74c3c !important;
    }
</style>


<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="refresh"><i class="fa fa-hourglass"></i> 更新节点</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '{:url("node/index")}',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'node', minWidth: 200, align: 'left', title: '系统节点'},
                {field: 'title', minWidth: 80, align: "center",title: '节点名称 <i class="table-edit-tips color-red">*</i>'},
                {field: 'create_time', minWidth: 80, title: '更新时间'}
            ]],
            page: false,
            search: false,
            skin: 'line'
        });


        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'refresh') {  // 监听添加操作
                var loading = layer.load();
                $.ajax({
                    url: '{:url("node/refresh")}',
                    type: 'POST',
                    data: {},
                    dataType: 'json',
                    success: function (dt) {
                        if (dt.code == 0) {
                            layer.msg("更新节点成功", {icon: 1},function (){
                                location.reload();
                            });
                        } else {
                            layer.msg(dt.msg, {icon: 2});
                        }
                    },
                    complete: function () {
                        layer.close(loading);
                    }
                });
                return false;
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            // console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'refresh') {

            }
        });

    });
</script>

</body>
</html>